package yu.zhou.njupt.importdata.util;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import yu.zhou.njupt.importdata.worker.Worker;

public class SqlUtil {

    private static Document procedureDoc = null;   

    static {
        try {
            procedureDoc = new SAXReader().read(Worker.class.getClassLoader().getResourceAsStream("procedure.xml"));
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
    
    /** 禁用、启用表上约束的语句 */
    public static String getSqlForCons() {
        Element rootElement = procedureDoc.getRootElement();
        Element element = (Element) rootElement.element("get_constraints");
        return element.getText();
    }
    
    /** unusable、rebuild表上索引的语句 */
    public static String getSqlForIndexes() {
        Element rootElement = procedureDoc.getRootElement();
        Element element = (Element) rootElement.element("get_indexes");
        return element.getText();
    }
    
    /** 更新日志表的语句(z_table) */
    public static String getSqlForUpdateLog() {
        Element rootElement = procedureDoc.getRootElement();
        Element element = (Element) rootElement.element("update_log");
        return element.getText();
    }

    /** 获得本次更新已经处理过的文件 */
    public static String getSqlForHasDealtFile() {
        Element rootElement = procedureDoc.getRootElement();
        Element element = (Element) rootElement.element("has_dealt_file");
        return element.getText();
    }

}
